<?php

namespace App\Http\Controllers\Api;

use App\Model\Version;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class VersionController extends Controller
{
    // 获取版本信息
    public function index(Request $request)
    {
        $type = $request->input('type',1);

        $ver = Version::where('type', $type)->latest('id')->first();
        if (!$ver) {
            return ['code'=>'0','msg'=>'暂未获取到版本信息'];
        }

        if ($ver->type == 1) {
            $fileUrl = $ver->file_url;
        } else {
            $fileUrl = 'itms-services://?action=download-manifest&url=' . $ver->file_url;
        }


        $result = [
            'name' => $ver->version_id,
            'file_url' => $fileUrl,
            'remark' => $ver->remark,
            'download' => "http://".$_SERVER['HTTP_HOST'] . '/invite/down',
        ];

        return ['code'=>1,'msg'=>'返回数据','data'=>$result];

    }
}